#include <iostream>
#include <string>
#include <vector>

using namespace std;


std::pair<string,string> get_long_short(const string &raw){
    // first: start, second: len 
    std::pair<int,int> long_record(-1,-1);
    std::pair<int,int> short_record(-1,-1);

    for(int i=0;i<=int(raw.size())-1;i++){
        // ignore intervals
        if(raw[i]==' ' || raw[i]==','){
            continue;
        }
        // single word: raw[left] ~ raw[right]
        const int left=i;
        int right=left;
        for(;right+1<=int(raw.size())-1;right++){
            if(raw[right+1]==' ' || raw[right+1]==','){
                break;
            }
        }
        i=right;
        // update record
        const int len=right-left+1;
        if(long_record.first==-1 || 
            len>long_record.second){
                long_record.first=left;
                long_record.second=len;
            }
        if(short_record.first==-1 ||
            len<short_record.second){
                short_record.first=left;
                short_record.second=len;
            }
    }

    return std::pair<std::string,std::string>(
        std::string(raw.begin()+long_record.first,
        raw.begin()+long_record.first+long_record.second),
        std::string(raw.begin()+short_record.first,
        raw.begin()+short_record.first+short_record.second)
    );
}

int main(){
    std::string raw;
    std::getline(std::cin,raw);

    std::pair<std::string,std::string> result=
        get_long_short(raw);
    
    cout<<result.first<<std::endl;
    cout<<result.second<<std::endl;
    
    return 0;

    // cout<<"original:"<<raw<<"|||"<<std::endl;

    // raw=std::string("abcdefgh");


    // cout<<    string(raw.begin()+2,raw.begin()+4)<<endl;

    return 0;
}